package com.moyu.admin.bean;

import com.moyu.admin.constant.RespCode;
import lombok.Data;

@Data
public class BaseResp<T> {

  private int code;
  private String msg;
  private T data;

  private BaseResp(int code, String msg, T data) {
    this.code = code;
    this.msg = msg;
    this.data = data;
  }

  public static BaseResp success() {
    return new BaseResp(RespCode.SUCCESS.getCode(), RespCode.SUCCESS.getMsg(), null);
  }

  public static BaseResp error() {
    return new BaseResp(RespCode.ERROR.getCode(), RespCode.ERROR.getMsg(), null);
  }

  public static <T> BaseResp success(T data) {
    return new BaseResp(RespCode.SUCCESS.getCode(), RespCode.SUCCESS.getMsg(), data);
  }

  public static <T> BaseResp error(T data) {
    return new BaseResp(RespCode.ERROR.getCode(), RespCode.ERROR.getMsg(), data);
  }

  public static <T> BaseResp error(String msg, T data) {
    return new BaseResp(RespCode.ERROR.getCode(), msg, data);
  }

  public static <T> BaseResp error(int code, String msg, T data) {
    return new BaseResp(code, msg, data);
  }
}
